package yuekao6.ods;

import com.alibaba.ververica.cdc.connectors.mysql.MySQLSource;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.streaming.api.functions.source.SourceFunction;
import yuekao6.util.KafkaUtil;
import yuekao6.util.MyDeserializationSchemaFunction;

public class Conversion {
    public static void main(String[] args) throws Exception {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        env.setParallelism(1);

        SourceFunction<String> sourceFunction = MySQLSource.<String>builder()
                .hostname("hadoop-single")
                .port(3306)
                .databaseList("tms01") // monitor all tables under inventory database
                .username("root")
                .password("root")
                .deserializer(new MyDeserializationSchemaFunction()) // converts SourceRecord to String
                .build();


        DataStreamSource<String> streamSource = env.addSource(sourceFunction);
        streamSource.print();

        streamSource.addSink(KafkaUtil.kafkaSink("tms_ods"));
        env.execute();
    }
}
